package com.movie.act;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.TextView;

import com.movie.util.Log;

/**
 * 12-分享微博
 * 
 * @author Administrator
 * 
 */
public class SinaShareAct extends BaseActivity {

	private ImageView fenxiang = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sinashareact);
		initBackTitleBar();
		fenxiang = (ImageView) findViewById(R.id.fenxiang);
		fenxiang.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

			}
		});

		onInputNum();
	}

	EditText et_content;// 定义一个文本输入框
	TextView tv_num;// 用来显示剩余字数
	int num = 140;// 限制的最大字数

	private void onInputNum() {
		et_content = (EditText) findViewById(R.id.et_content);
		tv_num = (TextView) findViewById(R.id.tv_num);

		et_content.addTextChangedListener(new TextWatcher() {
			private CharSequence temp;
			private int selectionStart;
			private int selectionEnd;

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				temp = s;
				Log.i("-----------onTextChanged s" + s);
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
				int number =  s.length();
				tv_num.setText("" + number);
				selectionStart = et_content.getSelectionStart();
				selectionEnd = et_content.getSelectionEnd();
				// System.out.println("start="+selectionStart+",end="+selectionEnd);
				if (temp.length() > num) {
					s.delete(selectionStart - 1, selectionEnd);
					int tempSelection = selectionStart;
					et_content.setText(s);
					et_content.setSelection(tempSelection);// 设置光标在最后
				}
			}
		});

	}
}
